home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 127_01.zip / RAPREAD.C < prev    next >
Text File  |  1993-06-17  |  8KB  |  255 lines

  1. /*********************************************************************\
  2. ** .---------------------------------------------------------------. **
  3. ** |                                                               | **
  4. ** |                                                               | **
  5. ** |         Copyright (c) 1981, 1982, 1983 by Eric Martz.         | **
  6. ** |                                                               | **
  7. ** |                                                               | **
  8. ** |       Permission is hereby granted to use this source         | **
  9. ** |       code only for non-profit purposes. Publication of       | **
  10. ** |       all or any part of this source code, as well as         | **
  11. ** |       use for business purposes is forbidden without          | **
  12. ** |       written permission of the author and copyright          | **
  13. ** |       holder:                                                 | **
  14. ** |                                                               | **
  15. ** |                          Eric Martz                           | **
  16. ** |                         POWER  TOOLS                          | **
  17. ** |                    48 Hunter's Hill Circle                    | **
  18. ** |                      Amherst MA 01002 USA                     | **
  19. ** |                                                               | **
  20. ** |                                                               | **
  21. ** `---------------------------------------------------------------' **
  22. \*********************************************************************/
  23.  
  24. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  25. /*
  26.     RAPREAD.C
  27.  
  28.         find_portion()             <- commented out
  29.         open_read(new)
  30.         read_command(line)
  31.         io_port(fp)
  32.         baud(fp)
  33.         screen_status()
  34.  
  35. */
  36. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  37.  
  38. #include "rap.h"
  39.  
  40. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  41.  
  42. /* BEGIN COMMENTING OUT OF find_portion <<<<<<<<<<<<<<<<<<<<<<<<<<<
  43.  
  44. For information on the "boiler-plate" assembly code formerly included
  45. in RAP, contact Eric Martz. In addition to find_portion() there are
  46. two programs, MAKEMENU which makes a menu from a text file properly
  47. demarkated into portions, and RAPMENU which RAPS a document of portions
  48. selected in an arbitrary order in the menu made by MAKEMENU.
  49.  
  50. find_portion(){
  51.  
  52. /*
  53. Old_portion IS THE PORTION FOR WHICH READING WAS MOST RECENTLY COMPLETED.
  54. New_portion IS THE PORTION TO BE READ NEXT.
  55. */
  56. /* UPON RETURN, NEXT CALL TO rapgets(...,Fpin) WILL GET THE FIRST LINE
  57.     OF THE PORTION New_portion.
  58.     
  59.     POSSIBLE ENTRY CONDTIONS:
  60.     
  61.         Old_portion = 0; MUST READ FROM BEGINNING OF FILE UP TO New_portion.
  62.  
  63.         Old-portion POSITIVE BUT < New_portion; MUST READ FROM PORTION
  64.         FOLLOWING Old_portion UP TO New_portion.
  65.         WHEN END OF Old_portion (PORTIT_C) WAS ENCOUNTERED IN anotherline(),
  66.         READING WAS CONTINUED UNTIL PORTIT_C.
  67.         
  68.         [IF Old_portion WAS >= New_portion, IT WAS ALREADY SET TO 0 AND
  69.         FILE WAS REOPENED BY read_command().]
  70. */
  71.     char discard[BIGBUF];
  72.     int i, portion;
  73.  
  74.     i = In_main; /* used to hold subread linecnt - see anotherline() */
  75.     In_main = In_linecnt;
  76.     In_linecnt = i;
  77.     Fpin = Fp_read;
  78.  
  79.     if (Old_portion AND (New_portion EQ (Old_portion+1)))
  80.         /* READY TO CONTINUE WITH FILE ALREADY OPEN */
  81.         return(YES);
  82.  
  83.     if (Old_portion EQ 0) Old_portion = -1;
  84.     for (portion=(Old_portion+1); portion < New_portion; portion++) {
  85.         discard[0] = NULL;
  86.         while ((instr(0,discard,PORTIT_O)) EQ ERROR) {
  87.             if (!rapgets(discard, Fpin)) {
  88. notenough:
  89.                 fprintf(STDERR,"Not enough portions in input file.\n");
  90.                 exit(0);
  91.             }
  92.         }
  93.         while ((instr(0,discard,PORTIT_C)) EQ ERROR)
  94.             if (!rapgets(discard, Fpin)) goto notenough;
  95.     }
  96. }
  97.  
  98. >>>>>>>>>>>>>>>>>>>>>>>>>>>>> END COMMENTING OUT OF find_portion */
  99.  
  100. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  101. open_read(new)
  102.     char *new;
  103.     {
  104.     if (Fp_read) {
  105.         fpfree(Fp_read);
  106.         Fp_read = 0;
  107. /*        Old_portion = 0;*/
  108.     }
  109.     if (!(Fp_read = fopen(new, "r-"))) {
  110.         fprintf(STDERR,"File %s does not exist. Ignoring .re command ");
  111.         return(NO);
  112.     }
  113.     strcpy(Fn_read, new);
  114.     Fpin = Fp_read;
  115.     In_main = In_linecnt;
  116.     In_linecnt = 0;
  117.     return(YES);
  118. }
  119. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  120. read_command(line)
  121.     char *line;
  122.     {
  123.     char newname[FILENAME];
  124.     int i;
  125. /*    int newportion;*/
  126.  
  127.     i = findwords(line+3, Pp);
  128.     if (i <= 0 OR i >= 3) { /* i must be 1 or 2 */
  129.         fprintf(STDERR,"Invalid .re command ");
  130. badread:
  131.         fprintf(STDERR,"at line %d.\n", In_linecnt);
  132.         return(0);
  133.     }
  134.     strcpy(newname, Pp[1]);
  135.     upper(newname);
  136.     if (badname(newname)) {
  137.         fprintf(STDERR,"Invalid filename in .re command ");
  138.         goto badread;
  139.     }
  140. /*    if (i EQ 2) {
  141.         if (ati(&newportion, Pp[2]) OR newportion < 1) {
  142.             fprintf(STDERR,"Invalid portion number \"%s\" in .re command ",
  143.                 Pp[2]);
  144.             goto badread;
  145.         }
  146.     }
  147.     else newportion = 0;
  148. */
  149.     if (Fpin NE Fp_main) {
  150.         fprintf(STDERR,"Error: second level .re command ");
  151.         goto badread;
  152.     }
  153.     if ( /*!newportion AND*/ !(open_read(newname))) goto badread;
  154. /*    else { /* portion */
  155.         if (!Fp_read OR !(equal(newname, Fn_read))
  156.         OR newportion <= Old_portion)
  157.             if (!open_read(newname)) goto badread;
  158.     }
  159.     New_portion = newportion;
  160. */
  161.     if (!Screen_size) {
  162.         fprintf(STDERR,"\tNow reading \"%s\"", Fn_read);
  163. /*        if (newportion) fprintf(STDERR," portion %d", New_portion);*/
  164.         fprintf(STDERR,"\n");
  165.     }
  166. }
  167. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  168. io_port(fp)
  169.     FILE *fp;
  170.     {
  171.     int val[8], i;
  172.  
  173.     rapgets(Inbuf, fp);
  174.     de_comment(Inbuf);
  175.     blankout(Inbuf,",");
  176.     if ((findwords(Inbuf, Pp)) NE 7) {
  177. ioerr:
  178.         fprintf(STDERR,"Error: invalid i/o port specifications\n");
  179.         exit(0);
  180.     }
  181.     for (i=1; i<=7; i++) {
  182.         if (ati(&val[i],Pp[i])) goto ioerr;
  183.         if (val[i] < 0 OR val[i] >= 256) goto ioerr;
  184.     }
  185.     Pdata = val[1];
  186.     Pstatus = val[2];
  187.     Pimask = val[3];
  188.     Pomask = val[4];
  189.     Preset = val[5];
  190.     Presetval = val[6];
  191.     Pready = val[7];
  192. }
  193. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  194. baud(fp)
  195.     FILE *fp;
  196.     {
  197.     int val[3], i;
  198.     char buf[MAXLINE];
  199.  
  200.     rapgets(buf,fp);
  201.     
  202.     FOREVER {
  203.         rapgets(Inbuf,fp);
  204.         if (!*Inbuf) break;
  205.         de_comment(Inbuf);
  206.         blankout(Inbuf, ",");
  207.         if (findwords(Inbuf,Pp) NE 2) {
  208. berr:
  209.             fprintf(STDERR,"Error in baud specification.\n");
  210.             exit(0);
  211.         }
  212.         for (i=1; i<=2; i++) {
  213.             if (ati(&val[i], Pp[i])) goto berr;
  214.             if (val[i] <0 OR val[i] >255) goto berr;
  215.         }
  216.         outp(val[1],val[2]);
  217.     }
  218.     fprintf(STDERR,"%s\n",buf);
  219. }
  220. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  221. screen_status() {
  222.     char buf[MAXLINE];
  223.     
  224.     if (!Screen_size) return(0);
  225.     if (Lines_out < Screen_size) goto addone;
  226.     Lines_out = 0;
  227.     sprintf(buf,
  228.         " At line %d of %s ",
  229.         In_linecnt, (Fpin EQ Fp_main)? Fn_main: Fn_read);
  230.     if (Rmval > 75) strcat(buf," space->next screen; ^C->quit ");
  231.     pad(buf, 'l', Rmval - ((Rmval - 1 - strlen(buf))/2), '*');
  232.     pad(buf, 'r', Rmval - 1, '*');
  233.     fprintf(STDERR,"%s\n",buf);
  234.     while(!bdos(CON_STATUS));
  235.     if (bdos(CONIN) EQ CTRL_C) {
  236.         Interrupted = YES;
  237.         printf("\n\n\t--- RAP ABORTED WITH ^C ---\n");
  238.         if (Deinit) puts (Deinit);
  239.         dioflush();
  240.         exit(1);
  241.     }
  242.     puts("\b \b"); /*  SOME CRT'S DO NOT HAVE DESTRUCTIVE BACKSPACE */
  243. addone:
  244.     Lines_out++;
  245. }
  246. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  247.  
  248. /* END OF RAPREAD.C */
  249.  
  250. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  251. al[1],val[2]);
  252.     }
  253.     fprintf(STDERR,"%s\n",buf);
  254. }
  255. /* - - - - - - - - - - - - - - - - - - - - - - - - -